import { defineConfig, loadEnv } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd() + '/env', '')

  return {
    plugins: [uni()],

    // CSS 配置 - 修复 Sass 警告
    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler' // 使用现代编译器API
        }
      }
    },

    // 开发服务器
    server: {
      host: '0.0.0.0',
      port: 3000,
      open: true,
      proxy: {
        '/api': {
          target: env.VITE_PROXY_TARGET,
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, '')
        }
      }
    },

    // 构建优化 - 保留Vant组件
    build: {
      rollupOptions: {
        treeshake: {
          moduleSideEffects: id => id.includes('vant') || id.includes('.css')
        }
      }
    }
  }
})
